package com.hlhj.funlike_business.moudle;

import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.hlhj.funlike_business.api.Apis;
import com.hlhj.funlike_business.api.BaseObser;
import com.hlhj.funlike_business.bean.AddGoodBean;
import com.hlhj.funlike_business.bean.FoodTypeBean;
import com.hlhj.funlike_business.bean.MsgBean;
import com.lzy.okgo.model.Response;

import java.util.List;

public class MyFoodTypeMoudle implements BaseModule{
    public interface getResult{
        void showDelResult(String msg);

        void showAddResult(AddGoodBean addGoodBean);

        void showGoodList(List<FoodTypeBean.DataBean> dataBeans);
    }

    public getResult listener;

    public void setListener(getResult listener) {
        this.listener = listener;
    }

    public void LoadDel(Context context, int id){
        Apis.INSTANCE.DelGoodType(id)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.showDelResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }

    public void LoadAdd(Context context,String type_name){
        Apis.INSTANCE.AddGoodType(type_name)
                .subscribe(new BaseObser<Response<AddGoodBean>>(context) {
                    @Override
                    public void httpSuccess(Response<AddGoodBean> addGoodBeanResponse) {
                        if (listener!=null){
                            listener.showAddResult(addGoodBeanResponse.body());
                        }
                    }
                });
    }

    public void LoadGoodList(Context context){
        Apis.INSTANCE.GetGoodTypeList()
                .subscribe(new BaseObser<Response<FoodTypeBean>>(context) {
                    @Override
                    public void httpSuccess(Response<FoodTypeBean> goodTypeBeanResponse) {
                        if (listener!=null){
                            listener.showGoodList(goodTypeBeanResponse.body().getData());
                        }
                    }
                });
    }
}
